<%@page import="java.util.StringTokenizer"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@ include file="/init.jsp"%>

<%
ListType mappedFee = (ListType) request.getAttribute("mappedFee");
System.out.println("doing ID >>>" + mappedFee.getListTypeId());

List<ListType> mappedSubFees = 	ListTypeServiceUtil.getListTypes
("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() );
System.out.println("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() +"<<<");
%>

		<aui:layout>
			<aui:column>
				<span class="hder" id="feesName_<%=mappedFee.getListTypeId() %>" ><%=mappedFee.getName() %></span>
			</aui:column>
		</aui:layout>
			
		<aui:layout>
			<aui:column columnWidth="33"><br>
				<%
			if(mappedSubFees.size() >= 2){
			%>
			
			<%
			}else if(mappedSubFees.size() == 1) {
				
				ListType mappedSubFee = mappedSubFees.get(0);
				StringTokenizer strTok = new StringTokenizer(mappedSubFee.getName(), "~");
				String firstPart, secondPart, fees;
				firstPart= secondPart= fees ="";
				try{
					 firstPart = strTok.nextToken(); //.replaceAll(mappedFee.getName(), "");
					 secondPart = strTok.nextToken();
					 fees = strTok.nextToken();
				}catch(Exception ex){
					
				}
			%>
			<div id="selected_<%=mappedFee.getListTypeId() %>">
				<%= fees %>
			</div>
			<%}
			%>
			<input type="hidden" id="cgtTax_<%=mappedFee.getListTypeId() %>" name="cgtTax_<%=mappedFee.getListTypeId() %>" value="250"/>
				
			<!-- this is if there is drop down -->		
			<%
			if(mappedSubFees.size() >= 2){
			%>
			
			<select  onChange="pickFee(this, <%=mappedFee.getListTypeId() %>);"  id="purpose_<%=mappedFee.getListTypeId() %>" name="purpose_<%=mappedFee.getListTypeId() %>"    >
					  <option value="">-Select purpose-</option>
			<%
			for(int h=0; h<mappedSubFees.size(); h++){
				ListType mappedSubFee = mappedSubFees.get(h);
				String name = mappedSubFee.getName();
				StringTokenizer strTok = new StringTokenizer(name, "~");
				String firstPart, secondPart, fees;
				firstPart= secondPart= fees ="";
				try{
					 firstPart = strTok.nextToken().replaceAll(mappedFee.getName(), "");
					 secondPart = strTok.nextToken();
					 fees = strTok.nextToken();
				}catch(Exception ex){
					
				}
				
			%>
			<option value="<%= fees %>"><%=firstPart  %></option>
                
            <%
			}
            %>
                 		
			</select>
			
			<%
			}
			%>
			</aui:column>
			<aui:column columnWidth="33">
				<strong>Enter the Scale of Fees:</strong>
				<input type="text" id="capitalGain_<%=mappedFee.getListTypeId() %>" name="capitalGain_<%=mappedFee.getListTypeId() %>"></input>
			</aui:column>
			<aui:column columnWidth="33">
				<br><input readonly="readonly" id="result_<%=mappedFee.getListTypeId() %>" name="result_<%=mappedFee.getListTypeId() %>" type="text" class="resultbox">
			</aui:column>
		</aui:layout>
			
		<aui:layout>
			<aui:column><br>
				<input name="bttnCompute" type="button" value="Compute" onclick="ComputeFee_<%=mappedFee.getListTypeId() %>();"/>
			</aui:column>
		</aui:layout>
		
<script>
function ComputeFee_<%=mappedFee.getListTypeId() %>(){
	
	try{
		var result = document.getElementById('result_<%=mappedFee.getListTypeId() %>');
		var salesAmount = document.getElementById('capitalGain_<%=mappedFee.getListTypeId() %>');
		var cgtTax =  document.getElementById('cgtTax_<%=mappedFee.getListTypeId() %>');
		//alert(salesAmount.value);		
		result.value = salesAmount.value ;
		hidePrintButton();
		computeTotal();
	}catch(err){
		alert(err.message);
	}	
}
</script>